Skip to content

Implement MNES Telnet Option Proxying - #208

Open
nschimme wants to merge 5 commits into
masterfrom
feature/mnes-proxying-2551435476655868122
Open

Implement MNES Telnet Option Proxying#208
nschimme wants to merge 5 commits into
masterfrom
feature/mnes-proxying-2551435476655868122

Conversation

@nschimme

@nschimme nschimme commented Apr 15, 2026

Copy link
Copy Markdown
Owner

This change implements the MNES (Mud New-Environ Standard) protocol as requested.

Key features:

  1. Context-Aware Proxying: MMapper now waits for the connected user client to negotiate NEW-ENVIRON before announcing its own support to the MUD server.
  2. IP Address Reporting: Automatically reports the real IP address of the connected user to the MUD via the IPADDRESS variable.
  3. Capability Reporting: Reports MMapper's own capabilities via MTTS bitvector (currently set to 653: ANSI | UTF-8 | 256 COLORS | PROXY | MNES).
  4. Internal Client Defaults: The built-in ClientTelnet has sane defaults for CLIENT_NAME, CLIENT_VERSION, and CHARSET.
  5. Protocol Synchronization: Character encoding is now automatically synchronized if the client specifies it via MNES variables.
  6. Robust Parsing: The NEW-ENVIRON parser handles VAR, VAL, USERVAR, and ESC sequences, and correctly identifies "Send All" requests.
  7. Better Debugging: Improved telnet subnegotiation logging by disambiguating constants that share the same value (like SEND, REQUEST, MODE, EDIT).

PR created automatically by Jules for task 2551435476655868122 started by @nschimme

Summary by Sourcery

Add support for Telnet NEW-ENVIRON (MNES) negotiation and proxying across client, proxy, and MUD connections, including environment variable exchange and capability reporting.

New Features:

  • Introduce full NEW-ENVIRON subnegotiation handling in the telnet core, including VAR/VAL/USERVAR/ESC parsing and send/is/info helpers.
  • Proxy NEW-ENVIRON negotiations between user clients and the MUD, reporting MMapper capabilities via MTTS and the user's IP via IPADDRESS.
  • Extend the internal ClientTelnet to answer NEW-ENVIRON SEND requests with default CLIENT_NAME, CLIENT_VERSION, CHARSET, and MTTS values.
  • Automatically synchronize character encoding based on MNES variables received from the client or server.

Enhancements:

  • Improve telnet subnegotiation debug logging by disambiguating shared subnegotiation codes based on the active option.
  • Expose peer IP address through the abstract socket layer and proxy so it can be surfaced to MNES.
  • Add comparison support for TaggedBytes to enable use in ordered containers like QMap.

- Added support for Mud New-Environ Standard (MNES) protocol in AbstractTelnet.
- Implemented client-aware proxying: MudTelnet delays WILL response until the user client supports MNES.
- MudTelnet automatically handles IPADDRESS (client's real IP) and MTTS (MMapper capabilities bitvector).
- ClientTelnet provides sane defaults for its MNES implementation.
- UserTelnet synchronizes character encoding based on received MNES variables (MTTS, CHARSET).
- Extended AbstractSocket to provide peerAddress() for IP reporting.
- Improved telnetSubnegName to handle value conflicts between different options.
- Fixed a bug in the NEW-ENVIRON parser that incorrectly handled "Send All" requests.
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@sourcery-ai

sourcery-ai Bot commented Apr 15, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implements MNES/NEW-ENVIRON-aware telnet proxying end-to-end: adds NEW-ENVIRON option support and parsing in AbstractTelnet, wires it through UserTelnet, MudTelnet, Proxy, and ClientTelnet, reports MTTS/IPADDRESS and sensible client defaults, synchronizes charset based on MNES variables, and improves telnet subnegotiation logging for overlapping subneg codes.

Sequence diagram for NEW-ENVIRON negotiation gating between user and MUD

sequenceDiagram
    actor UserClient
    participant UserTelnet
    participant Proxy
    participant MudTelnet
    participant MudServer

    UserClient->>UserTelnet: IAC WILL NEW-ENVIRON
    UserTelnet->>UserTelnet: requestTelnetOption(TN_DO, OPT_NEW_ENVIRON)
    UserTelnet-->>UserClient: IAC DO NEW-ENVIRON
    UserTelnet->>Proxy: onNewEnvironNegotiated(true)
    Proxy->>MudTelnet: onUserNewEnvironNegotiated(true)
    MudTelnet->>MudTelnet: m_userSupportsNewEnviron = true

    MudServer-->>MudTelnet: IAC DO NEW-ENVIRON
    MudTelnet->>MudTelnet: virt_receiveNewEnvironDo()
    MudTelnet->>MudTelnet: if m_userSupportsNewEnviron && !myOptionState[OPT_NEW_ENVIRON]
    MudTelnet-->>MudServer: IAC WILL NEW-ENVIRON
    MudTelnet->>MudTelnet: myOptionState[OPT_NEW_ENVIRON] = true

    note over MudTelnet,MudServer: Mud only gets WILL NEW-ENVIRON after user support is known
Loading

Sequence diagram for NEW-ENVIRON SEND handling and MTTS/IPADDRESS reporting

sequenceDiagram
    actor UserClient
    participant UserTelnet
    participant Proxy
    participant MudTelnet
    participant MudServer

    MudServer-->>MudTelnet: SB NEW-ENVIRON SEND MTTS, IPADDRESS SE
    MudTelnet->>MudTelnet: virt_receiveNewEnvironSend(vars, userVars)
    alt user does not support NEW-ENVIRON
        MudTelnet->>Proxy: onRelayNewEnvironSendFromMudToUser(vars, userVars)
        Proxy->>UserTelnet: onRelayNewEnvironSend(vars, userVars)
        UserTelnet-->>UserClient: SB NEW-ENVIRON SEND MTTS, IPADDRESS SE
    else user supports NEW-ENVIRON
        MudTelnet->>MudTelnet: sendAll = vars.isEmpty() && userVars.isEmpty()
        MudTelnet->>MudTelnet: detect MTTS/IPADDRESS requested
        MudTelnet->>Proxy: onGetPeerAddress()
        Proxy->>Proxy: getUserSocketAddress()
        Proxy-->>MudTelnet: user IP (AbstractSocket::peerAddress)
        MudTelnet->>MudServer: SB NEW-ENVIRON IS MTTS=653, IPADDRESS=<user IP> SE
        MudTelnet->>Proxy: onRelayNewEnvironSendFromMudToUser(vars, userVars)
        Proxy->>UserTelnet: onRelayNewEnvironSend(vars, userVars)
        UserTelnet-->>UserClient: SB NEW-ENVIRON SEND MTTS, IPADDRESS SE
        UserClient-->>UserTelnet: SB NEW-ENVIRON IS ... SE
        UserTelnet->>UserTelnet: virt_receiveNewEnvironIs(vars, userVars)
        UserTelnet->>Proxy: onRelayNewEnvironIsFromUserToMud(vars, userVars)
        Proxy->>MudTelnet: onRelayNewEnvironIs(vars, userVars)
        MudTelnet-->>MudServer: SB NEW-ENVIRON IS (relayed user vars) SE
    end
Loading

Sequence diagram for charset synchronization via NEW-ENVIRON MTTS/CHARSET

sequenceDiagram
    actor UserClient
    participant UserTelnet
    participant MudTelnet
    participant MudServer

    rect rgb(235, 245, 255)
        note over UserClient,UserTelnet: Client announces capabilities and charset
        UserClient-->>UserTelnet: SB NEW-ENVIRON IS MTTS=..., CHARSET=... SE
        UserTelnet->>UserTelnet: virt_receiveNewEnvironIs(vars, userVars)
        UserTelnet->>UserTelnet: if MTTS bit UTF-8 set
        UserTelnet->>UserTelnet: setEncodingForName(ENCODING_UTF_8)
        UserTelnet->>UserTelnet: if CHARSET present
        UserTelnet->>UserTelnet: setEncodingForName(CHARSET)
        UserTelnet->>MudTelnet: onRelayNewEnvironIs(vars, userVars)
        MudTelnet-->>MudServer: SB NEW-ENVIRON IS (relayed client vars) SE
    end

    rect rgb(245, 235, 255)
        note over MudServer,MudTelnet: Server negotiates TERMINAL_TYPE / CHARSET
        MudServer-->>MudTelnet: SB CHARSET ACCEPTED <charset> SE
        MudTelnet->>MudTelnet: sendCharsetAccepted(characterSet)
        MudTelnet->>MudTelnet: if myOptionState[OPT_NEW_ENVIRON]
        MudTelnet->>MudServer: SB NEW-ENVIRON INFO CHARSET=<charset> SE

        MudServer-->>MudTelnet: SB TERMINAL-TYPE IS <term> SE
        MudTelnet->>MudTelnet: virt_receiveTerminalType(terminalType)
        MudTelnet->>MudTelnet: if myOptionState[OPT_NEW_ENVIRON]
        MudTelnet->>MudServer: SB NEW-ENVIRON INFO TERMINAL_TYPE=<term> SE
    end
Loading

Updated class diagram for telnet NEW-ENVIRON support and socket IP reporting

classDiagram
    class AbstractTelnet {
        <<abstract>>
        +static uint8_t OPT_NEW_ENVIRON
        +static uint8_t TNSB_VAR
        +static uint8_t TNSB_VAL
        +static uint8_t TNSB_ESC
        +static uint8_t TNSB_INFO
        +static uint8_t TNSB_USERVAR
        -TelnetTextCodec m_textCodec
        -TelnetTermTypeBytes m_termType
        +void setTerminalType(TelnetTermTypeBytes terminalType)
        +void setEncodingForName(string name)
        +CharacterEncodingEnum getEncoding() const
        #void sendNewEnvironIs(QMap~RawBytes,RawBytes~ vars, QMap~RawBytes,RawBytes~ userVars)
        #void sendNewEnvironInfo(QMap~RawBytes,RawBytes~ vars, QMap~RawBytes,RawBytes~ userVars)
        #void sendNewEnvironSend(QList~RawBytes~ vars, QList~RawBytes~ userVars)
        +virtual void virt_receiveNewEnvironSend(QList~RawBytes~ vars, QList~RawBytes~ userVars)
        +virtual void virt_receiveNewEnvironIs(QMap~RawBytes,RawBytes~ vars, QMap~RawBytes,RawBytes~ userVars)
        +virtual void virt_receiveNewEnvironInfo(QMap~RawBytes,RawBytes~ vars, QMap~RawBytes,RawBytes~ userVars)
        +virtual void virt_receiveNewEnvironDo()
        +virtual void virt_receiveNewEnvironWill()
        +virtual void virt_receiveNewEnvironWont()
    }

    class UserTelnetOutputs {
        +void onRelayTermTypeFromUserToMud(TelnetTermTypeBytes bytes)
        +void onRelayNewEnvironIsFromUserToMud(QMap~RawBytes,RawBytes~ vars, QMap~RawBytes,RawBytes~ userVars)
        +void onRelayNewEnvironInfoFromUserToMud(QMap~RawBytes,RawBytes~ vars, QMap~RawBytes,RawBytes~ userVars)
        +void onNewEnvironNegotiated(bool supported)
        ..virtual..
        #virtual void virt_onRelayTermTypeFromUserToMud(TelnetTermTypeBytes bytes)
        #virtual void virt_onRelayNewEnvironIsFromUserToMud(QMap~RawBytes,RawBytes~ vars, QMap~RawBytes,RawBytes~ userVars)
        #virtual void virt_onRelayNewEnvironInfoFromUserToMud(QMap~RawBytes,RawBytes~ vars, QMap~RawBytes,RawBytes~ userVars)
        #virtual void virt_onNewEnvironNegotiated(bool supported)
    }

    class UserTelnet {
        -UserTelnetOutputs &m_outputs
        +void onRelayNewEnvironSend(QList~RawBytes~ vars, QList~RawBytes~ userVars)
        +void virt_receiveNewEnvironSend(QList~RawBytes~ vars, QList~RawBytes~ userVars)
        +void virt_receiveNewEnvironIs(QMap~RawBytes,RawBytes~ vars, QMap~RawBytes,RawBytes~ userVars)
        +void virt_receiveNewEnvironInfo(QMap~RawBytes,RawBytes~ vars, QMap~RawBytes,RawBytes~ userVars)
        +void virt_receiveNewEnvironDo()
        +void virt_receiveNewEnvironWill()
        +void virt_receiveNewEnvironWont()
    }

    class MudTelnetOutputs {
        +void onRelayNewEnvironSendFromMudToUser(QList~RawBytes~ vars, QList~RawBytes~ userVars)
        +QString onGetPeerAddress() const
        ..virtual..
        #virtual void virt_onRelayNewEnvironSendFromMudToUser(QList~RawBytes~ vars, QList~RawBytes~ userVars)
        #virtual QString virt_onGetPeerAddress() const
    }

    class MudTelnet {
        -MudTelnetOutputs &m_outputs
        -bool m_userSupportsNewEnviron
        +void virt_receiveNewEnvironSend(QList~RawBytes~ vars, QList~RawBytes~ userVars)
        +void virt_receiveNewEnvironIs(QMap~RawBytes,RawBytes~ vars, QMap~RawBytes,RawBytes~ userVars)
        +void virt_receiveNewEnvironInfo(QMap~RawBytes,RawBytes~ vars, QMap~RawBytes,RawBytes~ userVars)
        +void virt_receiveNewEnvironDo()
        +void onRelayNewEnvironIs(QMap~RawBytes,RawBytes~ vars, QMap~RawBytes,RawBytes~ userVars)
        +void onRelayNewEnvironInfo(QMap~RawBytes,RawBytes~ vars, QMap~RawBytes,RawBytes~ userVars)
        +void onUserNewEnvironNegotiated(bool supported)
    }

    class ClientTelnet {
        +void virt_receiveNewEnvironSend(QList~RawBytes~ vars, QList~RawBytes~ userVars)
    }

    class Proxy {
        -std::unique_ptr~UserTelnet~ m_userTelnet
        -std::unique_ptr~MudTelnet~ m_mudTelnet
        -std::unique_ptr~AbstractSocket~ m_userSocket
        +QString getUserSocketAddress() const
    }

    class AbstractSocket {
        <<abstract>>
        +bool isConnected() const
        +QString peerAddress() const
        ..virtual..
        #virtual bool virt_isConnected() const
        #virtual QString virt_peerAddress() const
    }

    class TcpSocket {
        +bool virt_isConnected() const
        +QString virt_peerAddress() const
    }

    class VirtualSocket {
        +bool virt_isConnected() const
        +QString virt_peerAddress() const
    }

    class TaggedBytes {
        +bool operator==(TaggedBytes a, TaggedBytes b)
        +bool operator!=(TaggedBytes a, TaggedBytes b)
        +bool operator<(TaggedBytes a, TaggedBytes b)
    }

    AbstractTelnet <|-- UserTelnet
    AbstractTelnet <|-- MudTelnet
    AbstractTelnet <|-- ClientTelnet

    AbstractSocket <|-- TcpSocket
    AbstractSocket <|-- VirtualSocket

    UserTelnetOutputs <.. Proxy : implements
    MudTelnetOutputs <.. Proxy : implements

    Proxy o--> UserTelnet
    Proxy o--> MudTelnet
    Proxy o--> AbstractSocket

    MudTelnet --> MudTelnetOutputs
    UserTelnet --> UserTelnetOutputs
Loading

File-Level Changes

Change Details Files
Add full NEW-ENVIRON (MNES) subnegotiation support and parsing in the shared telnet layer.
  • Introduce OPT_NEW_ENVIRON and NEW-ENVIRON-related subnegotiation constants for VAR/VAL/ESC/INFO/USERVAR with improved telnetSubnegName disambiguation that is aware of the option code.
  • Extend AbstractTelnet with virtual handlers for NEW-ENVIRON SEND/IS/INFO and DO/WILL/WONT hooks, plus helpers to send NEW-ENVIRON IS/INFO/SEND messages using TelnetFormatter.
  • Implement a robust NEW-ENVIRON subnegotiation parser in AbstractTelnet::processTelnetSubnegotiation that builds var/uservar maps, handles ESC-escaped bytes, recognizes SEND-all semantics, and dispatches to the new virtual handlers.
  • Hook NEW-ENVIRON into the telnet negotiation state machine so DO/WILL/WONT transitions update option state and call the appropriate virt_receiveNewEnviron* callbacks.
src/proxy/AbstractTelnet.cpp
src/proxy/AbstractTelnet.h
Proxy NEW-ENVIRON data between user and MUD and inject MNES-specific metadata like MTTS capabilities and user IP address.
  • Teach MudTelnet to respond to NEW-ENVIRON SEND by answering requested MTTS and IPADDRESS vars, using MudTelnetOutputs::onGetPeerAddress to obtain the real peer IP, and then relaying the SEND request to the user client.
  • Track whether the user client supports NEW-ENVIRON and only enable NEW-ENVIRON towards the MUD once the client has negotiated support, via onUserNewEnvironNegotiated and virt_receiveNewEnvironDo.
  • Add MudTelnet relay helpers for forwarding NEW-ENVIRON IS/INFO from the user to the MUD when MNES is enabled server-side.
src/proxy/MudTelnet.cpp
src/proxy/MudTelnet.h
Add NEW-ENVIRON awareness to the user-side telnet connection and pipeline.
  • Have UserTelnet request DO NEW-ENVIRON on connect and expose virt_receiveNewEnviron* overrides that synchronize encoding based on MTTS/CHARSET, propagate MNES negotiation state back to MudTelnet, and ignore invalid SENDs from the client side.
  • Allow the user-side telnet to forward NEW-ENVIRON SEND initiated by the MUD to the client when NEW-ENVIRON is enabled, via onRelayNewEnvironSend.
  • Extend UserTelnetOutputs and its Proxy implementation to relay NEW-ENVIRON IS/INFO from the user to the MUD and to inform the server-side when NEW-ENVIRON is negotiated.
src/proxy/UserTelnet.cpp
src/proxy/UserTelnet.h
src/proxy/proxy.cpp
Provide MNES defaults and MTTS capabilities for the internal client implementation.
  • Include Version.h into ClientTelnet so it can advertise the running client version via NEW-ENVIRON.
  • Implement ClientTelnet::virt_receiveNewEnvironSend to respond with CLIENT_NAME, CLIENT_VERSION, CHARSET (UTF-8), and MTTS=525 (ANSI
UTF-8
Expose real peer addresses through the proxy and sockets for IPADDRESS reporting and make minor infrastructure tweaks.
  • Extend AbstractSocket with a peerAddress accessor and implement it for TcpSocket (actual remote address) and VirtualSocket (loopback placeholder).
  • Add Proxy::getUserSocketAddress plus a corresponding MudTelnetOutputs::onGetPeerAddress hook, and use these in MudTelnet to fetch the connected user’s IP for MNES IPADDRESS.
  • Add operator< to TaggedBytes so it can be used as a key in ordered QMap/QList contexts required by the NEW-ENVIRON maps.
  • Tighten a helper method signature in the MudTelnet proxy adapter (getProxy() const) to support new const accessors.
src/proxy/AbstractSocket.h
src/proxy/TcpSocket.cpp
src/proxy/TcpSocket.h
src/proxy/VirtualSocket.cpp
src/proxy/VirtualSocket.h
src/proxy/proxy.h
src/proxy/proxy.cpp
src/proxy/TaggedBytes.h

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues, and left some high level feedback:

  • The NEW-ENVIRON SEND parsing appears to mishandle the "send all" case (e.g. IAC SB NEW-ENVIRON SEND IAC SE): the loop adds an empty variable to sendVars, so sendAll is never true on the receiver side; consider explicitly tracking a sendAll flag when type == TNSB_SEND and no variables are present instead of appending an empty key.
  • The MTTS capability bitvector is hardcoded in multiple places (653 in MudTelnet, 525 in ClientTelnet); consider centralizing these values or deriving them from a shared set of flags to avoid divergence when capabilities change.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The NEW-ENVIRON `SEND` parsing appears to mishandle the "send all" case (e.g. `IAC SB NEW-ENVIRON SEND IAC SE`): the loop adds an empty variable to `sendVars`, so `sendAll` is never true on the receiver side; consider explicitly tracking a `sendAll` flag when `type == TNSB_SEND` and no variables are present instead of appending an empty key.
- The MTTS capability bitvector is hardcoded in multiple places (653 in `MudTelnet`, 525 in `ClientTelnet`); consider centralizing these values or deriving them from a shared set of flags to avoid divergence when capabilities change.

## Individual Comments

### Comment 1
<location path="src/proxy/AbstractTelnet.cpp" line_range="1024-992" />
<code_context>
+                    }
+                }
+            }
+            // Add last one
+            if (inVal) {
+                if (isUserVar) {
+                    isUserVars[currentVar] = currentVal;
+                } else {
+                    isVars[currentVar] = currentVal;
+                }
+            } else if (!currentVar.isEmpty() || type == TNSB_SEND) {
+                // if it's SEND and no more bytes, it means send all
+                if (type == TNSB_SEND) {
+                    if (isUserVar) {
+                        sendUserVars.append(currentVar);
</code_context>
<issue_to_address>
**issue (bug_risk):** Handling of empty NEW-ENVIRON SEND creates a dummy variable and breaks the `sendAll` detection downstream.

For a pure `NEW-ENVIRON SEND` (`IAC SB NEW-ENVIRON SEND IAC SE` with no VAR/USERVAR), `type == TNSB_SEND` but `currentVar` stays empty. The final `else if (!currentVar.isEmpty() || type == TNSB_SEND)` still appends an empty `RawBytes`, so `vars.isEmpty()`/`userVars.isEmpty()` become false and `sendAll` is never set in the receivers. You should only append when `!currentVar.isEmpty()`, and rely on `vars.isEmpty() && userVars.isEmpty()` to represent the "send all" case, as already done in `virt_receiveNewEnvironSend`.
</issue_to_address>

### Comment 2
<location path="src/proxy/proxy.cpp" line_range="1216-1218" />
<code_context>
     return deref(m_remoteEdit);
 }
+
+QString Proxy::getUserSocketAddress() const
+{
+    return m_userSocket->peerAddress();
+}
</code_context>
<issue_to_address>
**issue (bug_risk):** Dereferencing `m_userSocket` without checking for null may race with connection lifecycle.

`getUserSocketAddress()` assumes `m_userSocket` is always valid, but it’s used (via `MudTelnetOutputs::virt_onGetPeerAddress()`) in response to NEW-ENVIRON SEND. If NEW-ENVIRON arrives before a socket is fully established, or after the client disconnects, this can dereference a null `m_userSocket`. Consider guarding this with a null check (and returning an empty/placeholder address) or adding an explicit assertion, and have callers handle the “no connected user socket” case.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/proxy/AbstractTelnet.cpp
Comment thread src/proxy/proxy.cpp
Comment on lines +1216 to +1218
QString Proxy::getUserSocketAddress() const
{
return m_userSocket->peerAddress();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Dereferencing m_userSocket without checking for null may race with connection lifecycle.

getUserSocketAddress() assumes m_userSocket is always valid, but it’s used (via MudTelnetOutputs::virt_onGetPeerAddress()) in response to NEW-ENVIRON SEND. If NEW-ENVIRON arrives before a socket is fully established, or after the client disconnects, this can dereference a null m_userSocket. Consider guarding this with a null check (and returning an empty/placeholder address) or adding an explicit assertion, and have callers handle the “no connected user socket” case.

@codecov

codecov Bot commented Apr 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 26.55827% with 271 lines in your changes missing coverage. Please review.
✅ Project coverage is 25.67%. Comparing base (a6c8653) to head (34c2714).

Files with missing lines Patch % Lines
src/proxy/AbstractTelnet.cpp 23.80% 128 Missing ⚠️
src/proxy/MudTelnet.cpp 0.00% 41 Missing ⚠️
src/proxy/UserTelnet.cpp 0.00% 34 Missing ⚠️
src/client/ClientTelnet.cpp 0.00% 27 Missing ⚠️
src/proxy/proxy.cpp 0.00% 13 Missing ⚠️
src/proxy/AbstractTelnet.h 0.00% 9 Missing ⚠️
tests/TestProxy.cpp 90.32% 6 Missing ⚠️
src/proxy/UserTelnet.h 0.00% 5 Missing ⚠️
src/proxy/MudTelnet.h 0.00% 3 Missing ⚠️
src/proxy/TcpSocket.cpp 0.00% 2 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #208      +/-   ##
==========================================
+ Coverage   25.40%   25.67%   +0.26%     
==========================================
  Files         519      519              
  Lines       43102    43462     +360     
  Branches     4698     4776      +78     
==========================================
+ Hits        10952    11160     +208     
- Misses      32150    32302     +152     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Fixed "Send All" parser bug in NEW-ENVIRON subnegotiation.
- Implemented delayed WILL NEW-ENVIRON: MudTelnet now waits for both MUD request and user client support.
- Added MTTS and CHARSET variable parsing in UserTelnet to synchronize character encoding.
- Fixed various compilation errors and warnings (signedness, unused parameters, duplicate case values).
- Refactored telnetSubnegName for better conflict resolution and debugging.
- Added MNES unit tests in TestProxy.
- Cleaned up local build artifacts.
- Completed MNES (Telnet Option 39) proxying logic with client-awareness.
- Implemented character encoding synchronization via MTTS/CHARSET variables.
- Resolved all compiler warnings (signedness, unused parameters, old-style casts).
- Fixed duplicate case value in telnet logging utility.
- Updated unit tests and CMakeLists.txt for proper verification.
- Verified parsing logic with new MNES test cases.
- Restore `vars` and `userVars` parameter names in `MudTelnet` and `UserTelnet` relay methods.
- Fix signedness conversion warnings in `AbstractTelnet.cpp` by correctly using `static_cast<char>` for `RawBytes::append` and avoiding it for `AppendBuffer::append`.
- Resolve `vtable` warning in `TestProxy.cpp` by moving `TestTelnet` destructor out-of-line.
- Fix unused parameter warnings in `TestProxy.cpp`.
@nschimme
nschimme force-pushed the master branch 2 times, most recently from e8139f3 to c119262 Compare April 20, 2026 18:27
@nschimme
nschimme force-pushed the master branch 3 times, most recently from ae664f2 to bcd8fca Compare May 21, 2026 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant